import json
from llamaapi import LlamaAPI

# Initialize the SDK
llama = LlamaAPI("LL-YUPmAX2nyeDA61FlsGXtcbmamBPC9fTB0BXXzaV7o6Ye8dRT94EVW36zv8h9gm0N")

# Build the API request

# API Request JSON Cell
api_request_json = {
  "model": "llama3-70b",
  "messages": [
    # {"role": "system", "content": "You are a llama assistant that talks like a llama, starting every word with 'll'."},
    # {"role": "user", "content": "Hi, happy llama day!"},
    {"role": "user", "content": "你知道这个世界有多少个国家嘛？用中文回答。"},
  ]
}


# Execute the Request
response = llama.run(api_request_json)
print(json.dumps(response.json(), indent=2)) 
resp = response.json()
if type(resp) == str:
    print("变量是字符串类型")
if type(resp) == dict:
    print("字典")
choices = resp.get("choices", [])
item = choices[0]
print(item.get("message", {}).get("content", ""))
# print(resp.choices[0].message.content)  

""" 
from openai import OpenAI

client = OpenAI(
api_key = "",
base_url = "https://api.llama-api.com"
)

response = client.chat.completions.create(
    model="llama-13b-chat",
    messages=[
        {"role": "system", "content": "Assistant is a large language model trained by OpenAI."},
        {"role": "user", "content": "Who were the founders of Microsoft?"}
    ]

)

#print(response)
print(response.model_dump_json(indent=2))
print(response.choices[0].message.content)
 """